package com.dq.domain.activity;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.section.SysSection;
import com.dq.domain.setup.GiftGrantSet;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/21
 * @描述
 */
@Data
@Entity
@ApiModel("促销活动")
public class Activity extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("活动编号")
    protected String activityNo;

    @ApiModelProperty("活动标题")
    protected String title;

    @ApiModelProperty("活动描述")
    protected String description;

    @ApiModelProperty("活动开始时间")
    protected Long beginTime;

    @ApiModelProperty("活动结束时间")
    protected Long endTime;

    @ApiModelProperty("活动轮播地址")
    protected String bannerUrl;

    @ApiModelProperty("活动参与方式文字描述")
    protected String participateDescription;

    @ApiModelProperty("收费方式")
    @Enumerated(EnumType.ORDINAL)
    protected ActivityCostType activityCostType;

    @ApiModelProperty("正常费用")
    protected BigDecimal normalPrice;

    @ApiModelProperty("会员费用")
    protected BigDecimal memberPrice;

    @ApiModelProperty("活动状态")
    @Enumerated(EnumType.ORDINAL)
    protected ActivityStatus activityStatus;

    @ApiModelProperty("活动目标地址")
    protected String activityTargetUrl;

    @ApiModelProperty("活动图片（多图）")
    protected String imgUrl;

    @ManyToOne
    @ApiModelProperty("礼物")
    protected GiftGrantSet giftGrantSet;

    @ApiModelProperty("活动类型")
    @Enumerated(EnumType.ORDINAL)
    protected ActivityType activityType;

    @ApiModelProperty("服务项目和次数")
    protected String serviceProject;

    @Transient
    @ApiModelProperty("礼物id")
    protected Long giftGrantSetId;

    @Transient
    @ApiModelProperty("门店id")
    protected Long orgId;

    @ApiModelProperty(value = "组织部门/门店",hidden = true)
    @ManyToOne
    protected SysSection org;

    public enum ActivityCostType{
        free("免费"),
        charge("收费");
        public String name;

        ActivityCostType(String name){
            this.name = name;
        }
    }

    public enum ActivityStatus{
        on("显示"),
        off("隐藏");

        public String name;

        ActivityStatus(String name){
            this.name = name;
        }
    }

    public enum ActivityType{
        ordinary("普通活动"),
        subcard("次卡活动");

        public String name;

        ActivityType(String name){
            this.name = name;
        }

    }

    @Data
    @ApiModel(value = "活动视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        protected Long activityId;
        @ApiModelProperty("活动编号")
        protected String activityNo;

        @ApiModelProperty("活动标题")
        protected String title;

        @ApiModelProperty("活动描述")
        protected String description;

        @ApiModelProperty("活动开始时间")
        protected String beginTime;

        @ApiModelProperty("活动结束时间")
        protected String endTime;

        @ApiModelProperty("活动轮播地址")
        protected String bannerUrl;

        @ApiModelProperty("收费方式")
        protected String activityCostType;

        @ApiModelProperty("正常费用")
        protected BigDecimal normalPrice;

        @ApiModelProperty("会员费用")
        protected BigDecimal memberPrice;

        @ApiModelProperty("活动状态")
        protected String activityStatus;

        @ApiModelProperty("多图")
        protected String imgUrl;

        @ApiModelProperty("服务项目和次数")
        protected String serviceProject;
        @ApiModelProperty("礼物id")
        protected Long giftGrantSetId;
        @ApiModelProperty("礼物类别名称")
        protected String categoryName;
        @ApiModelProperty("活动类别")
        protected ActivityType activityType;
        @ApiModelProperty("活动类别")
        protected String activityTypeEn;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.activityId = this.getId();
        vo.activityNo = this.activityNo;
        vo.title = this.title;
        vo.description = this.description;
        vo.beginTime = fmt(this.beginTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.endTime = fmt(this.endTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.bannerUrl = this.bannerUrl;
        vo.activityCostType = this.activityCostType.name;
        vo.normalPrice = this.normalPrice;
        vo.memberPrice = this.memberPrice;
        vo.activityStatus = this.activityStatus.name;
        vo.imgUrl = this.imgUrl;
        vo.serviceProject = this.serviceProject;
        vo.categoryName = this.getGiftGrantSet()!=null? this.getGiftGrantSet().getCategoryName():"";
        vo.activityType = this.getActivityType()!=null?this.getActivityType():null;
        vo.activityTypeEn = this.getActivityType() != null ?this.getActivityType().name:"";
        vo.giftGrantSetId = this.getGiftGrantSet() != null ?this.getGiftGrantSet().getId():null;
        return vo;
    }

    @Data
    @ApiModel("活动轮播图")
    public static class ActivityImgVo{
        @ApiModelProperty("活动轮播地址")
        protected String bannerUrl;
        @ApiModelProperty("活动目标地址")
        protected String activityTargetUrl;
        @ApiModelProperty("活动id")
        protected Long activityId;
    }

    public ActivityImgVo toActivityImgVo(){
        ActivityImgVo vo = new ActivityImgVo();
        vo.bannerUrl = this.bannerUrl;
        vo.activityTargetUrl = this.activityTargetUrl;
        vo.activityId = this.id;
        return vo;
    }

    @Data
    @ApiModel("活动详情")
    public static class ActivityDetails{
        @ApiModelProperty("活动编号")
        protected String activityNo;

        @ApiModelProperty("活动标题")
        protected String title;

        @ApiModelProperty("活动描述")
        protected String description;

        @ApiModelProperty("活动开始时间")
        protected String beginTime;

        @ApiModelProperty("活动结束时间")
        protected String endTime;

        @ApiModelProperty("活动轮播地址")
        protected String bannerUrl;

        @ApiModelProperty("活动参与方式文字描述")
        protected String participateDescription;

        @ApiModelProperty("收费方式")
        protected String activityCostType;

        @ApiModelProperty("正常费用")
        protected BigDecimal normalPrice;

        @ApiModelProperty("会员费用")
        protected BigDecimal memberPrice;

        @ApiModelProperty("活动状态")
        protected String activityStatus;
        @ApiModelProperty("多图")
        protected String imgUrl;
    }

    public ActivityDetails toActivityDetails(){
        ActivityDetails vo = new ActivityDetails();
        vo.activityNo= this.activityNo;
        vo.title = this.title;
        vo.description = this.description;
        vo.beginTime = fmt(this.beginTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.endTime = fmt(this.endTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.bannerUrl = this.bannerUrl;
        vo.activityCostType = this.activityCostType.name;
        vo.normalPrice = this.normalPrice;
        vo.memberPrice = this.memberPrice;
        vo.activityStatus = this.activityStatus.name;
        vo.imgUrl = this.imgUrl;
        return vo;
    }
}
